<?php
include ("../includes/config_conexao.php");

$idPeca = $_POST['id'];

$resposta = mysql_query("select p.qtdestoque - IFNULL(sum(mp.qtd_utilizada),0) restante
						from peca p
						left join movimento_peca mp on p.id_peca = mp.id_peca
						where p.status_peca = 'A'
							and p.id_peca = ".$idPeca);

$linha = mysql_fetch_array( $resposta );

echo $linha['restante'];
?>